package com.example.fangyh09.gallery;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

/**
 * Created by fangyh09 on 8/13/2016.
 */
public class ImageAdapter extends BaseAdapter {
    int[] res;
    Context context;
    public ImageAdapter(int []res,Context context) {
        this.res = res;
        this.context = context;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
      //  return 0;
    }

    @Override
    public Object getItem(int position) {
      //  return null;
        return res[position];
    }

    @Override
    public long getItemId(int position) {
       // return 0;
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       // return null;
        ImageView image = new ImageView(context);
        image.setBackgroundResource(res[position % res.length]);
        image.setLayoutParams(new Gallery.LayoutParams(200, 150));
        image.setScaleType(ImageView.ScaleType.FIT_XY);
        return image;
    }
}













































